package com.gs.disk.modules.headImgAndWallper.dao.mobile;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gs.common.mapper.CommonMapper;

import com.gs.disk.modules.headImgAndWallper.entity.CategoryEntity;
import com.gs.disk.modules.headImgAndWallper.entity.ResourceEntity;
import org.apache.ibatis.annotations.Mapper;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Mapper
public interface MobileCategoryDao extends CommonMapper<CategoryEntity, CategoryEntity> {

    /**
     * 根据分类名获取分类
     * @param categoryName
     * @return
     */
    default CategoryEntity getByName(String categoryName) {
        QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
        wrapper.select("id, category_name");
        wrapper.eq("category_name", categoryName);

        return this.selectOne(wrapper);
    }


    /**
     * 所有资源中的最大排序
     * @return
     */
    default Integer getMaxSort() {
        Integer currentSort = get("select max(sort) max_sort from wallper_category", Integer.class);


        if(ObjectUtil.isNull(currentSort)) return null;

        return currentSort + 1;
    }
}
